﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataModel
{
    public class Point
    {
        //internal double span;

        /// <summary>
        /// GPS方向角
        /// </summary>
        //JAVA TO C# CONVERTER NOTE: Fields cannot have the same name as methods:
        //private double GPSHeading_Renamed;

        /// <summary>
        /// GPS俯仰角
        /// </summary>
        //JAVA TO C# CONVERTER NOTE: Fields cannot have the same name as methods:
        //private double GPSPitch_Renamed;
        /// <summary>
        /// GPSX
        /// </summary>
        //JAVA TO C# CONVERTER NOTE: Fields cannot have the same name as methods:
        private double GPSX_Renamed;
        /// <summary>
        /// GPSY
        /// </summary>
        //JAVA TO C# CONVERTER NOTE: Fields cannot have the same name as methods:
        private double GPSY_Renamed;

        /// <summary>
        /// GPSZ
        /// </summary>
        //JAVA TO C# CONVERTER NOTE: Fields cannot have the same name as methods:
        private double GPSZ_Renamed;

        //private int lengthHeight, lengthLow, angelHeight, angelLow;

        private double length, angle, radian;

        private double x1, y1;
        private double z1;

        // 所采用的GPS的时间戳
        //private long gpsTimeStamp;
        // 自己的时间戳
        //private long timestamp;

        public Point()
        {
            //this.span = span;
        }

        public Point(int z, int lenth, int heading, int pitch)
        {
            this.z1 = z / 1000d;
            this.lengthToConter = lenth / 100d;
            this.scannerHeadingAngle = heading / 100d;
            this.pitchAngle = pitch / 100d;
        }

        //public Point(int x, int y, double distocenter, double z1)
        //{
        //    this.x1 = x/1000d;
        //    this.y1 = y/1000d;
        //    this.lengthToConter = distocenter;
        //    this.z1 = z1;
        //}

        public double GPSHeadingRadian { get; set; }

        public virtual double GPSX
        {
            get
            {
                return GPSX_Renamed;
            }
            set
            {
                GPSX_Renamed = value;
            }
        }

        public virtual double GPSY
        {
            get
            {
                return GPSY_Renamed;
            }
            set
            {
                GPSY_Renamed = value;
            }
        }

        public virtual double GPSZ
        {
            get
            {
                return GPSZ_Renamed;
            }
            set
            {
                GPSZ_Renamed = value;
            }
        }

        public int X {
            get
            {
                //double tx = Math.Round(x1, 1, MidpointRounding.AwayFromZero);
                //int ti = (int)(Math.Round(x1, 1, MidpointRounding.AwayFromZero) * 1000);
                return (int)(Math.Round(x1, 1, MidpointRounding.AwayFromZero) * 1000);
            }
        }

        public int Y
        {
            get
            {
                return (int)(Math.Round(y1, 1, MidpointRounding.AwayFromZero) * 1000);
            }
        }

        public int Z
        {
            get
            {
                return (int)(Math.Round(z1,1,MidpointRounding.AwayFromZero)*1000);
            }
        }

        private double pitchAngle;
        //public int PitchAngle
        //{
        //    get
        //    {
        //        pitchAngle = Math.Atan((z1 - GlobalVar.pitchCenterHeight) / (lengthToConter - GlobalVar.pitchCenterToCenter)) * 180 / Math.PI;
        //        return (int)(Math.Round(pitchAngle, 2, MidpointRounding.AwayFromZero) * 100);
        //    }
        //}

        /// <summary>
        /// 是否有效
        /// </summary>
        /// <returns></returns>
        public bool IsPointValid()
        {
            lengthToConter = Math.Sqrt(Math.Pow(x1 - 100, 2) + Math.Pow(y1 - 100, 2));

            if (lengthToConter > 6.5 && lengthToConter < 59.3 && z1 < 30)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 对应数据库中的值
        /// </summary>
        public double DistanceToCenter
        {
            get
            {
                return (int)(Math.Round(lengthToConter, 2, MidpointRounding.AwayFromZero) * 100);
            }
        }

        /// <summary>
        /// 计算点坐标
        /// </summary>
        /// <returns></returns>
        public void Compute()
        {
            //GP探头到点的距离 Lenth
            //double GP = length;
            //扇形界面,H1为G点在扇形界面向水平面的垂足。
            //Angle的取值范围 90~270
            //double PH = Math.Abs(length * Math.Sin(radian));
            double PH = length * Math.Sin(radian);
            double GH = Math.Abs(length * Math.Cos(radian));
            if (PH<0)
            {
                ;
            }
            double angle = radian * 180 / Math.PI;
            //
            //double x, y;

            //PI是180度，大于180代表 点在探头外围。
            //与1#探头反向。
            if (ID == "1")
            {
                x1 = GPSX - (PH * Math.Cos(GPSHeadingRadian));
                y1 = GPSY - (PH * Math.Sin(GPSHeadingRadian));
            }
            else
            {
                x1 = GPSX + (PH * Math.Cos(GPSHeadingRadian));
                y1 = GPSY + (PH * Math.Sin(GPSHeadingRadian));
            }
            z1 = GPSZ - GH;
        }

        public virtual double Length
        {
            get
            {
                return length;
            }
            set
            {
                this.length = value;
            }
        }

        /// <summary>
        /// 雷达偏移角
        /// </summary>
        public virtual double Radian
        {
            get
            {
                return radian;
            }
            set
            {
                this.radian = value;
            }
        }


        public virtual double Angle
        {
            get
            {
                return angle;
            }
            set
            {
                angle = value;
            }
        }

        public string ID { get; set; }
        public double ScannerHeadingRadian { get; set; }
    


        public double ScannerHeadingAngle
        {
            get
            {
                return (int)(Math.Round(scannerHeadingAngle, 2, MidpointRounding.AwayFromZero) * 100);
            }

            set { scannerHeadingAngle = value; }
        }

        public double X1 
        {
            get { return x1; }
        }
        public double Y1
        {
            get { return y1; }
        }
        public double Z1
        {
            get { return z1; }
            //set { z1 = value; }
        }

        public double lengthToConter;
        public double scannerHeadingAngle;
        //private int v1;
        //private int v2;
        //private int v3;
        //private int v4;
        //public virtual double Span
        //{
        //    get
        //    {
        //        return span;
        //    }
        //    set
        //    {
        //        this.span = value;
        //    }
        //}

        //public string ID { get; set; }
        //public double GPSHeadingAngle { get; set; }
        //public double ScannerRadian { get; set; }
        //public long GpsTimeStamp { get; set; }
        //public long Timestamp { get; set; }


        //public virtual double O
        //{
        //    get
        //    {
        //        return o;
        //    }
        //    set
        //    {
        //        this.o = value;
        //    }
        //}
        //public double GPSHeadingAngle { get; set; }


        //public virtual int LengthHeight
        //{
        //    get
        //    {
        //        return lengthHeight;
        //    }
        //    set
        //    {
        //        this.lengthHeight = value;
        //    }
        //}


        //public virtual int LengthLow
        //{
        //    get
        //    {
        //        return lengthLow;
        //    }
        //    set
        //    {
        //        this.lengthLow = value;
        //    }
        //}


        //public virtual int AngelHeight
        //{
        //    get
        //    {
        //        return angelHeight;
        //    }
        //    set
        //    {
        //        this.angelHeight = value;
        //    }
        //}
        ///// <summary>
        ///// 点的回转角度
        ///// </summary>
        //public double HeadingAngle {

        //    get; set;
        //}
        //public virtual double GPSPitch
        //{
        //    get
        //    {
        //        return GPSPitch_Renamed;
        //    }
        //    set
        //    {
        //        GPSPitch_Renamed = value;
        //    }
        //}
    }
}
